<template>
  <div class="_wz_cent_main _wz_alarmLog">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra" v-if="!vehicleData">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="车牌号" v-if="!vehicleData">
          <i-input v-model="formDataSearch.vehicleNo" placeholder="请填写车牌号" clearable />
        </FormItem>
        <FormItem label="日期范围">
          <DatePicker type="daterange" v-model="dateRange" placement="bottom-start" placeholder="请选择日期范围"></DatePicker>
        </FormItem>
        <FormItem label="运输企业" v-if="searchType && !vehicleData">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>

    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>
  </div>
</template>
<script>

  import wzTbale from "../../../components/table/table";

  export default {
    props: ['vehicleData'],//接收来自父组件的数据
    components: {
      wzTbale,//列表
    },
    data() {
      return {
        searchType:false,//搜索条件
        dateRange: [],//时间范围
        formDataSearch: {},//搜索表单数据
        subDeptList: [],//运输企业

        tableData: {
          url: this.apiUrl.webApi + "/monitor/operate/vehicleOperatePageList",//请求地址
          method: 'post',//请求方式
          where: {vehicleNo:!!this.vehicleData ? this.vehicleData.carPlateNo:''},//搜索条件
          height: 'auto',//表格高度 auto
          page: true,//分页是否使用
          columns: [//表头数据
            {type: 'index', width: 70, align: 'center', title: '序号'},
            {title: '车牌号', minWidth: 120, key: 'vehiclePlateNumber'},
            {title: '车架号', minWidth: 190, key: 'vehicleVinNo'},
            {
              title: '开始里程', minWidth: 120, render: (h, params) => {
                return h('span', !!params.row.mileageStart ? params.row.mileageStart + "km" : '0km');
              }
            },
            {
              title: '结束里程', minWidth: 120, render: (h, params) => {
                return h('span', !!params.row.mileageEnd ? params.row.mileageEnd + "km" : '0km');
              }
            },
            {
              title: '行驶里程', minWidth: 120, render: (h, params) => {
                return h('span', !!params.row.mileageDay ? params.row.mileageDay + "km" : '0km');
              }
            },
            {
              title: '最高时速', minWidth: 120, render: (h, params) => {
                return h('span', !!params.row.maxSpeed ? params.row.maxSpeed + "km" : '0km');
              }
            },
            {
              title: '平均速度', minWidth: 120, render: (h, params) => {
                return h('span', !!params.row.velocityAvg ? params.row.velocityAvg + "km" : '0km');
              }
            },
            {
              title: '连续行驶时间', key: 'runTime', minWidth: 170, render: (h, params) => {
                return h('span', !!params.row.runTime ? params.row.runTime: '0小时');
              }
            },
            {title: '运输企业', key: 'companyName', minWidth: 260},
            {title: '创建日期', key: 'createDate', minWidth: 110}
          ],
          format: {//返回数据格式
            list: ['data'],//数据list
            count: ['count'],//数据总量
          },
        },
      }
    },
    beforeCreate() {//beforeCreate创建前状态

    },
    created() {//created创建完毕状态

    },
    beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

    },
    mounted() {//mounted 挂载结束状态
      var that = this;

      //运输企业
      that.axios.post(that.apiUrl.coreDeptCoreDeptList, {}).then(res => {
        if (!!res) {
          that.subDeptList = res.data.data;
        }
      }).catch(err => {
        console.log("失败", err)
      })

    },
    methods: {//执行的方法
      searchSubmit() {//搜索
        this.formDataSearch.beginTime = !!this.dateRange[0] ? this.public.timeFormatting(this.dateRange[0], "yyyy-MM-dd") : '';
        this.formDataSearch.endTime = !!this.dateRange[1] ? this.public.timeFormatting(this.dateRange[1], "yyyy-MM-dd") : '';
        this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
        this.$refs.wzTbale.tableLoadData(true);
      },
    },
    watch: {//监听

    },
    beforeUpdate() {//beforeUpdate 更新前状态

    },
    updated() {//updated 更新完成状态

    },
    beforeDestroy() {//beforeDestroy 销毁前状态

    },
    destroyed() {//destroyed 销毁完成状态

    }
  }
</script>
<style lang="less">
  ._wz_alarmLog { //不固定头部  列表到底
    display: flex;
    flex-direction: column;


  }
</style>
